<template>
    <h2>角色添加</h2>
    <br/>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
        <el-form-item label="角色名称：">
            <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="角色类别：">
            <el-input v-model="form.role_type" />
        </el-form-item>
        <el-form-item label="数据范围：">
            <el-radio-group v-model="form.data_scope">
                <el-radio :value="1">全部数据</el-radio>
                <el-radio :value="2">公司已下数据</el-radio>
                <el-radio :value="3">个人数据</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="角色级别：">
            <el-radio-group v-model="form.role_level">
                <el-radio :value="0">高级</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="状态：">
            <el-radio-group v-model="form.useable">
                <el-radio :value="1">启用</el-radio>
                <el-radio :value="0">关闭</el-radio>
            </el-radio-group>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="AddRoles">添加</el-button>
        </el-form-item>

    </el-form>
</template>
    
<script setup lang='ts'>
import axios1 from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
import http from '../http.js'
//表单字段
const form = reactive({
    name: '',//角色名称
    role_type: '',//角色类别
    data_scope: 3,//数据范围
    role_level: 0,//角色级别 默认0 值越高等级越高
    useable:1,//状态 1启动0关闭
})
//添加角色
const AddRoles = () => {
    axios1.post(http.RBACxie+'/api/Role/roleCreate',form)
    .then(res => {
        if (res.data.code == 200) {
            ElMessage({ message: res.data.message, type: 'success', })
        }
        else if (res.data.code == 400) {
            ElMessage({ message: res.data.message, type: 'warning', })
            return
        }
         else {
            ElMessage({ message: '角色添加失败', type: 'warning', })
            return
        }
    })
    .catch(err => {
        console.log(err);
    })
}
    
</script>
    
<style>
    
</style>